package com.example.demo.mapper;

import com.example.demo.pojo.Bill;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Mapper
public interface BillMapper {
    /**
     *<a href="">财务统计</a>             <br>
     * -------------------
     * 今日出租的房子数量
     * 今日入住的人数
     *
     * 这个月收入的金额
     *
     */
    @Select("select count(roomState = 2) from room")
    public int countForRoomRental();

    @Select("select sum(billMoney) from bill")
    public int countallBil();

    @Select("select count(custState = 1) from Customer")
    public int countForCustLiving();

    @Insert("insert into bill (roomID,custNum,checkinDate,checkoutDate,deposit,billMoney,billState,bookID)" +
            " values(#{roomID},#{custNum},#{checkinDate},#{leaveDate},#{deposit},#{billMoney},#{billState},#{bookID})")
    public int addBill(int roomID, String custNum, String checkinDate, String leaveDate, int deposit, int billMoney, int billState, int bookID);

    @Select("select billID from bill where bookID = #{bookID}")
    public int getbillIDBybookID(String bookID);

    @Select("select * from bill where bookID = #{bookID}")
    public Bill getbillBybookID(String bookID);

    @Update("update bill set roomID=#{roomID},custNum=#{custNum},custNum2=#{custNum2}," +
            "billState=#{ddd},deposit=#{deposit},billMoney=#{billMoney}  where billID = #{billID}")
    void updateBybillID(int billID, String roomID, String custNum, String custNum2, String ddd, String deposit, String billMoney);

    @Select("select * from bill where roomID = #{roomID} and billState != 3")
    public List<Bill> getbillByRoomID(String roomID);

    @Select("select * from bill where billID = #{billID}")
    public Bill getbillBybillID(String billID);

    @Update("update bill set billState=#{billState} where billID = #{billID}")
    public void updateBillState(String billID, String billState);

    @Delete("delete from bill where bookID = #{bookID}")
    public void deleteBillByBookId(int bookID);

    @Select("select billState from bill where bookID = #{bookID}")
    String getbillStateByBookID(String bookID);

    @Update("update bill set billState=#{billState} where bookID = #{bookID}")
    int updateBillStateByBookID(Integer bookID, String billState);

    @Update("update bill set roomID=#{roomID} where bookID = #{bookID}")
    void updateRoomIDByBookID(int roomID, String bookID);
}
